package main

import (
	"fmt"
	"time"
)

func main() {
	ch11 := make(chan int, 1000)
	sign := make(chan byte, 1)

	for i := 0; i < 1000; i++ {
		ch11 <- i
	}

	go func() {
		var e int
		ok := true

		var timer *time.Timer

		for {
			select {
			case e = <-ch11:
				fmt.Printf("ch11 -> %d\n\r", e)
			case <-func() <-chan time.Time {
				if nil == timer {
					timer = time.NewTimer(time.Millisecond)
				} else {
					timer.Reset(time.Millisecond)
				}
				return timer.C
			}():
				fmt.Println("Timeout.")
				ok = false
				break
			}
			if !ok {
				sign <- 0
				break
			}
		}
	}()

	<-sign
}
